package org.corey.share.business;

import java.util.Date;

import org.corey.share.db.entity.Link;
import org.corey.share.db.service.AuthService;
import org.corey.share.db.service.AuthServiceImpl;
import org.corey.share.db.service.FriendLinkService;
import org.corey.share.db.service.FriendLinkServiceImpl;
import org.corey.share.misc.PageData;

import com.opensymphony.xwork2.ActionSupport;

public class LinkAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private FriendLinkService service = new FriendLinkServiceImpl();
	private AuthService authService = AuthServiceImpl.getInstance();
	private Long[] deleteLinksId;
	private PageData<Link> links;
	private Link saveOrUpdateLink;
	private int pageIndex = 1;
	private int pageSize = 0;

	public Long[] getDeleteLinksId() {
		return deleteLinksId;
	}

	public void setDeleteLinksId(Long[] deleteLinksId) {
		this.deleteLinksId = deleteLinksId;
	}

	public PageData<Link> getLinks() {
		return links;
	}

	public void setLinks(PageData<Link> links) {
		this.links = links;
	}

	public Link getSaveOrUpdateLink() {
		return saveOrUpdateLink;
	}

	public void setSaveOrUpdateLink(Link saveOrUpdateLink) {
		this.saveOrUpdateLink = saveOrUpdateLink;
	}

	public String manage() {
		this.links = service.getLinksWithPage(pageIndex, pageSize);
		return SUCCESS;
	}

	public String add() {
		saveOrUpdateLink.setCreatedDate(new Date());
		saveOrUpdateLink.setEditedDate(new Date());
		saveOrUpdateLink.setUser(authService.getUserId());
		boolean result = service.saveLink(saveOrUpdateLink);
		if (result) {
			return SUCCESS;
		} else {
			return INPUT;
		}
	}

}
